#ifndef _CONNECTION_MANAGER_H
#define _CONNECTION_MANAGER_H

#include "../LibUtil.h"

LIB_UTIL_NAMESPACE_BEGIN

struct tConnectionData {
	enum Method { 
		GET, POST
	} type;
	const char* url;
	const short port;
	const tDataBuffer* inData;
	tDataBuffer* outData;
	const long timeout;
	const bool asynchronize;
};

class ConnectionEventHandler;
class HttpConnection;
class ConnectionManager
{
public:
	virtual ~ConnectionManager() {}
	virtual bool Initialize() = 0;
	virtual bool Unitialize() = 0;
	virtual HttpConnection* OpenConnection(tConnectionData& data) = 0;
	static ConnectionManager* GetConnectionManager();
	static bool GetHttpData(const char* url, 
							 const int& port, 
							 tDataBuffer* outData, 
							 const tDataBuffer* inData = NULL, 
							 bool decrypt = false);
};

class HttpConnection 
{
public:
	virtual ~HttpConnection() {}
	virtual bool Open() = 0;
	virtual bool Close() = 0;
	virtual bool Destroy() = 0;
	virtual bool Connect() = 0;
	virtual void Cancel() = 0;
	virtual void SetEventHandler(ConnectionEventHandler* pHandler) = 0;
};

class ConnectionEventHandler
{
public:
	virtual ~ConnectionEventHandler() {}
	virtual void OnProgress(const HttpConnection* connection, const int& totalSize, const int& currentSize) = 0;
	virtual void OnSuccess(const HttpConnection* connection) = 0;
	virtual void OnFailed(const HttpConnection* connection, const int& errorCode) = 0;
};

LIB_UTIL_NAMESPACE_END

#endif //_CONNECTION_MANAGER_H
